package top.hkyzf.study.leetcode.tree;

import org.junit.Test;

/**
 * description: 
 * @author zhufeng
 * @date 2024/2/28 0028 11:16
 * @version V1.0
 */
public class 使二叉树所有路径值相等的最小代价_2673 {
    public int minIncrements(int n, int[] cost) {
        int step = n >> 1;
        int preStep = n;
        int result = 0;
        while (step > 0) {
            for (int i = step; i < preStep; i += 2) {
                // 双亲位置
                cost[i>>1] += Math.max(cost[i], cost[i + 1]);
                result += Math.abs(cost[i] - cost[i + 1]);
            }
            preStep = step;
            step = step >> 1;
        }
        return result;
    }

    @Test
    public void testMinIncrements () {
        int n = 15;
        int[] cost = {764,1460,2664,764,2725,4556,5305,8829,5064,5929,7660,6321,4830,7055,3761};
        System.out.println(minIncrements(n, cost));
    }
}
